﻿using System.ComponentModel;

namespace PerformanceDude.MSBuildShellExtension
{
    class MSBuildRunner
    {
        private BackgroundWorker msbuildRunner;

        public void Run(string fileName, string dotNetVersion, string targetName, string configurationName, string platformName, bool showPrompt)
        {
            this.msbuildRunner = new System.ComponentModel.BackgroundWorker();
            this.msbuildRunner.WorkerReportsProgress = true;
            this.msbuildRunner.WorkerSupportsCancellation = true;
            this.msbuildRunner.DoWork += new System.ComponentModel.DoWorkEventHandler(this.BackgroundWorker1DoWork);
            this.msbuildRunner.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.BackgroundWorker1RunWorkerCompleted);
            this.msbuildRunner.RunWorkerAsync(new MSBuildTask(fileName, dotNetVersion, MSBuildTask.GenerateArgument(targetName, configurationName, platformName), showPrompt));
        }

        private void BackgroundWorker1DoWork(object sender, DoWorkEventArgs e)
        {
            MSBuildTask task = (MSBuildTask)e.Argument;
            task.Execute();
        }

        private void BackgroundWorker1RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            
        }
    }
}
